APITester = {
    baseURL: '/api.php',
    baseFrontendURL: '/frontend.php',
	makeJSONCall: function(){
		var url = APITester.baseURL + $('#jsonapiurl').val();	
		url = url.replace('?','.'+$('#request_format').val()+'?');
		$.getJSON(url,APITester.handleJSONResponse);
    },    
	makeExampleCall: function(evt){
		evt.preventDefault();
		var url = APITester.baseURL + $(this).attr('href');
		url = url.replace('?','.json?');
		$.getJSON(url,APITester.handleJSONResponse);
    },        
	handleJSONResponse: function(data,textResult){
		$('#debugjson').html(textResult+':<br /> zie de firebug console voor uitvoer of <a href="'+$('#jsonapiurl').val()+'" target="_blank">klik deze link</a>');
		console.dir(data);
    },
    makeCall: function(){
		var url = APITester.baseFrontendURL + $('#htmlapiurl').val();
		$('#debughtmlstatus').html('Fetching: '+url);
		$('#debughtml').html('');
		$.get(url,APITester.handleResponse);
    },    
	handleResponse: function(data,textResult){
    	$('#debughtmlstatus').html(textResult);
		$('#debughtml').html(data);
		var response = eval(data); 
		console.dir(response);
    },    
}

$(document).ready(function(){
	$('a.example-call').click(APITester.makeExampleCall);
	$('#jsoncallbut').click(APITester.makeJSONCall);
	$('#htmlcallbut').click(APITester.makeCall);
});
